<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>订单管理</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="favicon.ico"> <link href="../css/bootstrap.min.css?v=3.3.7" rel="stylesheet">
    <link href="../css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <!-- Data Tables -->
    <link href="../css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">

    <link href="../css/animate.css" rel="stylesheet">
    <link href="../css/style.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>基本 <small>分类，查找</small></h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="table_data_tables.html#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                                <li><a href="table_data_tables.html#">选项1</a>
                                </li>
                                <li><a href="table_data_tables.html#">选项2</a>
                                </li>
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="">
                            <a data-toggle="modal" data-target="#myModal2" href="javascript:void(0);" class="btn btn-primary ">添加行</a>
                        </div>
                        <table class="table table-striped table-bordered table-hover dataTables-example">
                            <thead>
                                <tr>
                                    <th>订单ID</th>
                                    <th>联系人</th>
                                    <th>出发时间</th>
                                    <th>车牌</th>
                                    <th>到达时间</th>
                                    <th>一等座</th>
                                    <th>二等座</th>
                                    <th>无座</th>
                                    <th>使用者</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody id="listBody">
                            </tbody>
                            <tfoot>
                                <tr>
                                    <th>订单ID</th>
                                    <th>联系人</th>
                                    <th>出发时间</th>
                                    <th>车牌</th>
                                    <th>到达时间</th>
                                    <th>一等座</th>
                                    <th>二等座</th>
                                    <th>无座</th>
                                    <th>使用者</th>
                                    <th>操作</th>
                                </tr>
                            </tfoot>
                        </table>
                        <div class="modal inmodal" id="myModal" tabindex="300" role="dialog" aria-hidden="true">
                            <div class="modal-dialog">
                                <div class="modal-content animated bounceInRight">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true" onclick="clearModel()">&times;</span><span class="sr-only">关闭</span>
                                        </button>
                                        <h4 class="modal-title">订单表</h4>
                                    </div>
                                    <div class="modal-body">
                                        <form class="form-group" id="modal-form">
                                            <label>订单ID</label><input type="number" name="ticketId" readonly="readonly" class="form-control mOrderId">
                                            <label>用户ID</label><input type="number" name="orderStartTime"  readonly="readonly" placeholder="实名" class="form-control mUserId">
                                            <label>订单状态</label>
                                            <select class="mOrderState form-control">
                                                <option value=0>未出行</option>
                                                <option value=1>待支付</option>
                                                <option value=2>待点评</option>
                                            </select>
                                        </form>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-white" data-dismiss="modal" onclick="clearModel()">关闭</button>
                                        <button type="button" class="btn btn-primary" onclick="submitModal(this)">保存</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal inmodal" id="myModal2" tabindex="300" role="dialog" aria-hidden="true">
                            <div class="modal-dialog">
                                <div class="modal-content animated bounceInRight">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true" onclick="clearModel()">&times;</span><span class="sr-only">关闭</span>
                                        </button>
                                        <h4 class="modal-title">订单表</h4>
                                    </div>
                                    <div class="modal-body">
                                        <form class="form-group" id="modal-form2">
                                            <label>联系人</label><select class="addOrderUser form-control"></select>
                                            <label>开始时间</label><input type="datetime-local" class="addStartTime form-control">
                                            <label>结束时间</label><input type="datetime-local" class="addEndTime form-control">
                                            <label>车牌号</label><select class="addCard form-control"></select>
                                            <label>一等票</label><input type="number" class="addVip form-control">
                                            <label>二等票</label><input type="number" class="addOrdinary form-control">
                                            <label>无座票</label><input type="number" class="addNoSite form-control">
                                            <label>购票人</label><select class="addPerson form-control"></select>
                                        </form>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-white" data-dismiss="modal" onclick="clearModel()">关闭</button>
                                        <button type="button" class="btn btn-primary" onclick="addOrder()">保存</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="../js/jquery.min.js?v=2.1.4"></script>
    <script src="../js/bootstrap.min.js?v=3.3.7"></script>



    <script src="../js/plugins/jeditable/jquery.jeditable.js"></script>

    <!-- Data Tables -->
    <script src="../js/plugins/dataTables/jquery.dataTables.js"></script>
    <script src="../js/plugins/dataTables/dataTables.bootstrap.js"></script>

    <!-- 自定义js -->
    <script src="../js/content.js?v=1.0.0"></script>


    <!-- Page-Level Scripts -->
    <script>
        $(document).ready(function () {
           initTable()
            getCar()
            getUser()
            getDriver()
        });
        function initTable(){
            var pageNum;
            var htmls='';
            $.ajax({
                url : "/order1/getBeforeRunOrder",
                success:function(data) {
                    $("#listBody").html('')
                    for (var index in data.data) {
                        htmls +=
                            '<tr  class="grade">'+
                            '<td class = "id">' + data.data[index].orderId + '</td>' +
                            '<td class="orderUser center">' + data.data[index].orderUser + '</td>' +
                            '<td class="orderStartTime center">' + data.data[index].orderStartTime + '</td>' +
                            '<td class="orderCard">' + data.data[index].orderCard + '</td>' +
                            '<td class="orderEndTime center">' + data.data[index].orderEndTime + '</td>' +
                            '<td class="orderVipSite">' + data.data[index].orderVipSite + '</td>' +
                            '<td class="orderOrdinary center">' + data.data[index].orderOrdinary + '</td>' +
                            '<td class="orderNoSite">' + data.data[index].orderNoSite + '</td>' +
                            '<td class="orderPerson center">' + data.data[index].orderPerson + '</td>' +
                            '<td class="orderState center " hidden="hidden">' + data.data[index].orderState + '</td>' +
                            '<td class="" style="display: flex">' +
                            '<button class="btn btn-primary" id="update" data-toggle="modal" data-target="#myModal" data-backdrop="false" onClick="initModel(this)">修改</button>' +
                            '<button class="btn btn-primary" onClick="toDelete(this)">删除</button>' +
                            // '<button class="btn btn-primary" onClick="toFroze(this)">冻结</button>' +
                            '</td>' +
                            '</tr>\n'
                    }
                    let body=document.getElementById('listBody');
                    body.innerHTML = htmls
                    $('.dataTables-example').dataTable();
                }
            })
        }
        function initModel(obj){
            var tOj=$(obj).parent().parent();
            const id=parseInt( $(tOj).children(".id").text())
            $(".mOrderId").val(id);
            $(".mUserId").val($(tOj).children(".orderPerson").text())
            $(".mOrderState").val($(tOj).children(".orderState").text())
        }
        function toDelete(obj) {
            parent.layer.open({
                type: 0,
                skin: 'layui-layer-demo', //样式类名
                closeBtn: 1, //不显示关闭按钮
                shift: 2,
                shadeClose: true, //开启遮罩关闭
                content: '确认删除？',
                yes:function () {
                    const tOj = $(obj).parent().parent();
                    const id = parseInt($(tOj).children(".id").text())
                    $.ajax({
                            url:"/order1/deleteOrder",
                            type: "post",
                            data: {"id":id},
                            success: function () {
                                initTable();
                            }
                        }
                    )
                }
            });
        }
        function toFroze(obj) {
            const tOj = $(obj).parent().parent();
            const id = parseInt($(tOj).children(".id").text())
            $.ajax({
                    url:"/user1/frozeUser",
                    type: "post",
                    data: {"id":id},
                    success: function () {
                        initTable();
                    }
                }
            )
        }
        function getUser() {
            $.ajax({
                url:"/user1/aliveList",
                success:function (data) {
                    for (index in data.data){
                        $(".addPerson").append('<option value='+data.data[index].userId+'>'+data.data[index].userId+'</option>');
                    }
                }
            })
        }
        function getCar() {
            $.ajax({
                url:"/car1/getCars",
                success:function (data) {
                    for (index in data.data){
                        $(".addCard").append('<option value='+data.data[index].carCard+'>'+data.data[index].carCard+'</option>');
                    }
                }
            })
        }
        function getDriver() {
            $.ajax({
                url:"/driver1/aliveDriver",
                success:function (data) {
                    for (index in data.data){
                        $(".addOrderUser").append('<option value='+data.data[index].driverId+'>'+data.data[index].driverId+'</option>');
                    }
                }
            })
        }
        function clearModel(){
            $(".morderId").val('');
            $(".mUserId").val('')
            $(".mOrderState").val(0)
        }
        // 提交表单
        function submitModal(obj){
            var form=$("#modal-form")
            var data={
                orderId:$(".mOrderId").val(),
                orderPerson: $(".mUserId").val(),
                orderState:$(".mOrderState").val()

            }
            if (data.orderId==null||data.orderId==''){
                addOrder(data)
            }else {
                updateOrder(data)
            }
        }
        function updateOrder(data) {
            console.log("更新")
            $.ajax({
                url : "/order1/updateOrder",
                type: "POST",
                data: JSON.stringify(data),
                processData: false,  // 不处理数据
                contentType: "application/json;charset=UFT-8",   // 不设置内容类型
                success:function(data){
                    initTable()
                }
            })
        }
        function addOrder() {
            let data={
                orderUser:$(".addOrderUser").val(),
                orderStartTime:$(".addStartTime").val(),
                orderCard:$(".addCard").val(),
                orderEndTime:$(".addEndTime").val(),
                orderVipSite:$(".addVip").val(),
                orderOrdinary:$(".addOrdinary").val(),
                orderNoSite:$(".addNoSite").val(),
                orderPerson:$(".addPerson").val()
            }
            $.ajax({
                url : "/order1/addOrder",
                type: "POST",
                data: JSON.stringify(data),
                processData: false,  // 不处理数据
                contentType: "application/json;charset=UFT-8",   // 不设置内容类型
                success:function(data){
                    initTable()
                }
            })
        }
    </script>

<!--    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>-->
    <!--统计代码，可删除-->

</body>

</html>
